import jofc2.model.*
import jofc2.model.elements.LineChart
import jofc2.model.axis.YAxis
import jofc2.model.axis.XAxis
import jofc2.model.axis.Label
import jofc2.model.elements.AreaHollowChart
import jofc2.model.elements.PieChart
import jofc2.model.axis.Label.Rotation
import jofc2.model.elements.BarChart
import jofc2.OFC
import jofc2.model.elements.FilledBarChart
import jofc2.model.elements.SketchBarChart
import jofc2.model.elements.HorizontalBarChart
import jofc2.model.elements.ScatterChart
import java.math.MathContext
import jofc2.model.elements.StackedBarChart
import jofc2.model.elements.StackedBarChart.StackValue
import jofc2.model.elements.Legend


class LeaderMgrController {
    def authenticateService
    def index = { }

    def goswitch = {
        if (params.id) {
            def leader = Leader.get(params.id)
            leader.enabled = !leader.enabled
            leader.save(flush: true)
        } 
        return redirect(controller: "leader", action: "list") 
    }

    def passingRate = {
    }

    def passingRateChart = {
            School school = School.get(params.id)
            if (params.order) {
                params.sort = 'score'
            } 
            def classes = Classes.findAllBySchoolAndEnable(school, true, params) 

            def chart = new Chart("${school}及格率评比").setYAxis(new YAxis().setRange(0, 100, 10)).setBackgroundColour("#ECF9FF");
 
            def xaxis = new XAxis().setTickHeight(10).set3D(3).setColour("#909090");
            //def line = new LineChart(LineChart.Style.HOLLOW);  
            def element = new BarChart(BarChart.Style.THREED).setColour("#5579FF")
            //element.setHaloSize(0).setWidth(2).setDotSize(4);
  
            classes.each { classx -> 
                def bar
                def value = 40 + Math.round((Math.random()*60))
                if (value >= 80) {// 优秀
                    bar = new BarChart.Bar(value, "#3333FF") 
                }else if (value >= 60){//及格
                    bar = new BarChart.Bar(value) 
                }else{// 不及格
                    bar = new BarChart.Bar(value, "#FF6666") 
                }
                bar.setTooltip("${classx}<br>及格率${value}%")
                element.addBars(bar)
                xaxis.addLabels(new Label(classx?.toString()))  
            }
 
            chart.setXAxis(xaxis).addElements(element)
            //.setXLegend(new Text("tests", Text.TEXT_ALIGN_CENTER ) )
 
            //        println chart.toDebugString()
            return render(chart)
       
    }  
//各学校之间进行及格率评比
    def passingRateAll = {
    }

    def passingRateChartAll = {
            if (params.order) {
                params.sort = 'score'
            } 
            def schools = School.findAllByAreaAndEnable(authenticateService.userDomain().area, true) 

            def chart = new Chart("各学校之间及格率评比").setYAxis(new YAxis().setRange(0, 100, 10)).setBackgroundColour("#ECF9FF");
 
            def xaxis = new XAxis().setTickHeight(10).set3D(3).setColour("#909090");
            //def line = new LineChart(LineChart.Style.HOLLOW);  
            def element = new BarChart(BarChart.Style.THREED).setColour("#5579FF")
            //element.setHaloSize(0).setWidth(2).setDotSize(4);
  
            schools.each { classx -> 
                def bar
                def value = 40 + Math.round((Math.random()*60))
                if (value >= 80) {// 优秀
                    bar = new BarChart.Bar(value, "#3333FF") 
                }else if (value >= 60){//及格
                    bar = new BarChart.Bar(value) 
                }else{// 不及格
                    bar = new BarChart.Bar(value, "#FF6666") 
                }
                bar.setTooltip("${classx.name}<br>及格率${value}%")
                element.addBars(bar)
                xaxis.addLabels(new Label(classx.name?.toString()))  
            }
 
            chart.setXAxis(xaxis).addElements(element)
            //.setXLegend(new Text("tests", Text.TEXT_ALIGN_CENTER ) )
 
            //        println chart.toDebugString()
            return render(chart)
       
    }  

    def average = {
    }

    def averageChart = {
            School school = School.get(params.id)
           if (params.order) {
                params.sort = 'score'
            } 
            def classes = Classes.findAllBySchoolAndEnable(school, true, params) 

            def chart = new Chart("${school}平均分评比").setYAxis(new YAxis().setRange(0, 100, 10)).setBackgroundColour("#ECF9FF");
 
            def xaxis = new XAxis().setTickHeight(10).set3D(3).setColour("#909090");
            //def line = new LineChart(LineChart.Style.HOLLOW);  
            def element = new BarChart(BarChart.Style.THREED).setColour("#5579FF")
            //element.setHaloSize(0).setWidth(2).setDotSize(4);
  
            classes.each { classx -> 
                def bar
                def value = 40 + Math.round((Math.random()*60))
                if (value >= 80) {// 优秀
                    bar = new BarChart.Bar(value, "#3333FF") 
                }else if (value >= 60){//及格
                    bar = new BarChart.Bar(value) 
                }else{// 不及格
                    bar = new BarChart.Bar(value, "#FF6666") 
                }
                bar.setTooltip("${classx}<br>平均分：${value}分")
                element.addBars(bar)
                xaxis.addLabels(new Label(classx?.toString()))  
            }
 
            chart.setXAxis(xaxis).addElements(element)
            //.setXLegend(new Text("tests", Text.TEXT_ALIGN_CENTER ) )
 
            //        println chart.toDebugString()
            return render(chart)
    }

//各学校之间进行平均分评比
    def averageAll = {
    }

    def averageChartAll = {
           if (params.order) {
                params.sort = 'score'
            } 
            def schools = School.findAllByAreaAndEnable(authenticateService.userDomain().area, true) 

            def chart = new Chart("各校平均分评比").setYAxis(new YAxis().setRange(0, 100, 10)).setBackgroundColour("#ECF9FF");
 
            def xaxis = new XAxis().setTickHeight(10).set3D(3).setColour("#909090");
            //def line = new LineChart(LineChart.Style.HOLLOW);  
            def element = new BarChart(BarChart.Style.THREED).setColour("#5579FF")
            //element.setHaloSize(0).setWidth(2).setDotSize(4);
  
            schools.each { classx -> 
                def bar
                def value = 40 + Math.round((Math.random()*60))
                if (value >= 80) {// 优秀
                    bar = new BarChart.Bar(value, "#3333FF") 
                }else if (value >= 60){//及格
                    bar = new BarChart.Bar(value) 
                }else{// 不及格
                    bar = new BarChart.Bar(value, "#FF6666") 
                }
                bar.setTooltip("${classx.name}<br>平均分：${value}分")
                element.addBars(bar)
                xaxis.addLabels(new Label(classx.name?.toString()))  
            }
 
            chart.setXAxis(xaxis).addElements(element)
            //.setXLegend(new Text("tests", Text.TEXT_ALIGN_CENTER ) )
 
            //        println chart.toDebugString()
            return render(chart)
    }
}
